package com.foreknow.demo;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        String answer = "y";
        boolean register = false;//注册的标识位
        boolean isLogin = false;//登录的标识位
        String userName = "";
        String password = "";
        do {
            System.out.println("***********************");
            System.out.println("1.   注册");
            System.out.println("2.   登录");
            System.out.println("3.   抽奖");
            System.out.println("***********************");
            Scanner input = new Scanner(System.in);
            System.out.println("请选择菜单:");
            int choice = input.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("注册");
                    System.out.println("用户名：");
                    userName = input.next();
                    System.out.println("密码：");
                    password = input.next();
                    int cardNumber = (int)(Math.random()*(9999-1000))+1000;
                    System.out.println(userName+"------"+password+"-------"+cardNumber);
                    register = true;
                    break;
                case 2:
                    // System.out.println("登录");
                    if(register) {
                        for(int i = 1;i<=3;i++){
                            System.out.println("请输入登录用户名：");
                            String inputName = input.next();
                            System.out.println("请输入登录密码：");
                            String inputPassword = input.next();

                            if(inputName.equals(userName)&&inputPassword.equals(password)) {
                                System.out.println("welcome:"+userName);
                                isLogin = true;
                                break;
                            }else if(i<3){
                                System.out.println("您输入的用户名与密码不正确,还有"+(3-i)+"次机会");
                            }else {
                                System.out.println("3次错误的用户信息");
                            }
                        }
                    }else {
                        System.out.println("请先注册，然后登录");
                    }
                    break;
                case 3:
                    System.out.println("抽奖");
                    break;
                default:
                    System.out.println("输入错误!!!!!!");
                    break;
            }
            System.out.println("是否继续(y/n)");
            answer = input.next();
        } while (answer.equals("y"));

        if(answer.equals("n")){
            System.out.println("系统退出，谢谢您的使用......");
        }
    }
}
